﻿<c:BaseControl x:Class="personalplaner.gui.stamm.views.EditSaldoView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:bs="clr-namespace:personalplaner.business.stamm;assembly=personalplaner.business"
             xmlns:vm="clr-namespace:personalplaner.common.mvvm.factory;assembly=personalplaner.common"
             xmlns:fac="clr-namespace:personalplaner.gui.stamm.viewmodels.factories"
             vm:ViewModelLoader.FactoryType="{x:Type fac:EditSaldoModelFactory}"
             xmlns:c="clr-namespace:personalplaner.common.controls;assembly=personalplaner.common"
             xmlns:conv="clr-namespace:personalplaner.common.converters;assembly=personalplaner.common"
             Name="baseControl"
             Background="Transparent"
             Foreground="#E1000000">

    <Control.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/personalplaner.common;component/resources/styles/WhiteStyleTemplates.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Control.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Border BorderBrush="Transparent" BorderThickness="0" Background="Transparent" Margin="5,5,5,0" Padding="5" >
            <Grid>
                <ListBox ItemsSource="{Binding PlanLayoutItems}" SelectedItem="{Binding SelectedPlanLayoutItem}" Margin="5,20,0,0">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Border Background="Transparent">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <!--<ColumnDefinition Width="30"/>-->
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>

                                    <!--<TextBlock Text="{Binding PrsID}"/>-->
                                    <StackPanel Orientation="Horizontal" >
                                        <TextBlock Text="{Binding Vorname}" Margin="5,0,5,0"/>
                                        <TextBlock Text="{Binding Nachname}" Margin="0,0,10,0"/>
                                    </StackPanel>
                                    <TextBlock Text="{Binding AbteilungName}" Grid.Column="1"/>

                                </Grid>
                            </Border>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

            </Grid>
        </Border>

        <GridSplitter Width="4" Background="Transparent"/>

        <GroupBox Margin="5,5,5,0" Grid.Column="1">
            <Grid>
                <Grid.Resources>
                    <conv:NullToBoolConverter x:Key="nullToBool"/>
                    <conv:DateTimeToIsoConverter x:Key="dateToIso"/>
                </Grid.Resources>
                
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="300"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <TextBlock Text="Stunden" Margin="0,0,20,0"/>
                <c:NumericTextBox DataContext="{Binding SelectedSaldoAnpassug}" Text="{FocusBinding Amount}" Width="120" HorizontalAlignment="Left" Grid.Column="1" 
                                  IsEnabled="{Binding DataContext.IsWriteable, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}}"/>

                <TextBlock Text="Datum" Margin="0,0,20,0" Grid.Row="1"/>
                <DatePicker SelectedDate="{Binding SelectedSaldoAnpassug.Datum}" Width="120" HorizontalAlignment="Left" Grid.Row="1" Grid.Column="1" IsEnabled="{Binding IsWriteable}"/>

                <TextBlock Text="Grund" Margin="0,3,20,0" Grid.Row="2" VerticalAlignment="Top"/>
                <TextBox Text="{Binding SelectedSaldoAnpassug.Reason, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" Grid.Row="2" Grid.Column="1" Height="60" AcceptsReturn="True" IsEnabled="{Binding IsWriteable}"/>

                <Border BorderBrush="Black" BorderThickness="0,0,0,1" Background="Transparent" Grid.Row="3" Grid.ColumnSpan="3" Margin="10,50,50,0">
                    <Grid >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="Datum" FontWeight="Heavy"/>
                        <TextBlock Text="Stunden" FontWeight="Heavy" Grid.Column="1"/>
                        <TextBlock Text="Grund" FontWeight="Heavy" Grid.Column="2"/>
                    </Grid>
                </Border>
                <ListBox ItemsSource="{Binding SaldoAnpassungen}" SelectedItem="{Binding SelectedSaldoAnpassug}" Grid.Row="4" Grid.ColumnSpan="3" Margin="10,5,50,0">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="100"/>
                                    <ColumnDefinition Width="100"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding Datum, Converter={StaticResource dateToIso}}" VerticalAlignment="Top" />
                                <TextBlock Text="{Binding Amount}" Grid.Column="1" VerticalAlignment="Top"/>
                                <TextBlock Text="{Binding Reason}" Grid.Column="2" VerticalAlignment="Top"/>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                
            </Grid>
        </GroupBox>

        <StackPanel Grid.Row="1" Grid.ColumnSpan="4" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,20,40,20">
            <Button MinWidth="60" Margin="5" Command="{Binding DeleteCommand}">
                <TextBlock Text="Löschen"/>
            </Button>
            <Button MinWidth="60" Margin="5" Command="{Binding NewCommand}">
                <TextBlock Text="Neu"/>
            </Button>
            <Button MinWidth="60" Margin="5" Command="{Binding SaveCommand}">
                <TextBlock Text="Speichern"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsDefault="True" Command="{Binding OkCommand}">
                <TextBlock Text="OK"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsCancel="True" Command="{Binding CancelCommand}">
                <TextBlock Text="Abbrechen"/>
            </Button>
        </StackPanel>
    </Grid>
    
</c:BaseControl>
